<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="tabmenu">
    <?php include template('layout/submenu');?>
    <div class="text-intro"> 活动主题 : <?php echo $output['activity_info']['marketing_activity_title'];?></div>
</div>
<form method="GET">
    <input type="hidden" name="act" value="store_marketing_activity"/>
    <input type="hidden" name="op" value="store_marketing_activity"/>
    <input type="hidden" value="<?=$output['marketing_activity_id']?>" name="marketing_activity_id"/>
    <table class="ncsc-default-table" >
        <thead>
        <tr>
            <th class="w50"></th>
            <th class="w180 tl">商品名称</th>
            <th>商品原价</th>
            <th>活动价</th>
            <th>限购(0:不限购)</th>
            <th>报名时间/审核时间</th>
            <th>审核状态</th>
            <th>商品状态</th>
            <th>审核备注</th>
            <th>活动状态</th>
        </tr>
        </thead>
        <tbody>
        <?php if(isset($output['activity_goods']) && !empty($output['activity_goods']) && is_array($output['activity_goods'])):?>
            <?php foreach($output['activity_goods'] as $k=>$v):?>
                <tr class="bd-line">
                    <td><div class="pic-thumb"><a href="<?=$v['goods_url_all']?>" target="_blank"><img src="<?=$v['goods_image_all']?>"></a></div></td>
                    <td class="tl">
                        <dl class="goods-name">
                            <dt><a target="_blank" href="<?=$v['goods_url_all']?>"><?=$v['goods_name']?></a></dt>
                            <dd></dd>
                        </dl>
                    </td>
                    <td>￥<?=ncPriceFormat($v['goods_price'])?></td>
                    <td>￥<?=ncPriceFormat($v['kanjia_price'])?></td>
                    <td><?=$v['upper_limit']?></td>
                    <td><?php echo date('Y-m-d H:i:s', $v['create_time']);?><br/><?php echo date('Y-m-d H:i:s', $v['check_time']);?></td>
                    <td><?php echo $output['check_state_array'][$v['kanjia_state']];?></td>
                    <td><?php echo $output['goods_state_array'][$v['goods_state']];?></td>
                    <td><?=$v['remark']?></td>
                    <td><?php echo ( $v['check_state'] == 1 ) ? (($v['start_time'] > time()) ? '待上线' : (($v['end_time'] > time()) ? '进行中' : '已过期')) : $output['check_state_array'][$v['kanjia_state']];?></td>
                </tr>
            <?php endforeach;?>
        <?php else:?>
            <tr>
                <td colspan="20" class="norecord"><div class="warning-option"><i class="icon-warning-sign"></i><span><?php echo $lang['no_record'];?></span></div></td>
            </tr>
        <?php endif;?>
        </tbody>
        <tfoot>
        <tr>
            <td colspan="20"></td>
        </tr>
        </tfoot>
    </table>
</form>

<?php if(isset($output['if_show_apply']) && ($output['if_show_apply'] !== false)):?>
    <div class="div-goods-select">
        <form id="get_goods_select_from" method="GET">
            <input type="hidden" id="search_marketing_activity_id" name="marketing_activity_id" value="<?=(isset($output['marketing_activity_id']) ? (int)$output['marketing_activity_id'] : 0)?>"/>
            <table class="search-form">
                <tr>
                    <th class="w250"><strong>选择参加活动的商品，勾选并提交平台审核</strong></th>
                    <td class="w160"><input type="text" id="search_goods_name" class="text w150" name="name" value="" placeholder="搜索商品名称"/></td>
                    <td class="w70 tc"><a href="javascript:void(0);" id="btn_search_goods" class="ncbtn"><i class="icon-search"></i>搜索</a></td>
                    <td class="w10"></td>
                    <td><p class="hint">不输入名称直接搜索将显示店内所有普通商品，特殊商品不能参加。</p></td>
                </tr>
            </table>
        </form>
        <form method="POST" id="apply_form" onsubmit="ajaxpost('apply_form','','','onerror');" action="index.php?act=store_marketing_activity&op=activity_apply_save">

        </form>
    </div>
<?php endif;?>

<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/template.min.js" charset="utf-8"></script>
<script type="text/javascript">
    $(document).ready(function(){

        // 当前编辑对象，默认为空
        $edit_item = {};

        //搜索商品
        $('#btn_search_goods').on('click', function() {
            var url = "<?php echo urlShop('store_marketing_activity', 'goods_select');?>";
            url += '&' + $.param({goods_name: $('#search_goods_name').val()});
            url += '&' + $.param({marketing_activity_id: $('#search_marketing_activity_id').val()});
            $('#apply_form').load(url);
        });

        $('#apply_form').on('click', 'a.demo', function() {
            $('#apply_form').load($(this).attr('href'));
            return false;
        });

        $('#apply_form').on('click', '.promotion_price,.upper_limit', function() {
            $(this).parent('dd').parent('dl').find('input[type="checkbox"]').attr("checked", "true");
        });

        $('#btn_edit_xianshi_goods_submit').on('click', function() {
            var xianshi_goods_id = $('#dialog_xianshi_goods_id').val();
            var xianshi_price = Number($('#dialog_edit_xianshi_price').val());
            var goods_price = Number($('#dialog_edit_goods_price').text());
            if(!isNaN(xianshi_price) && xianshi_price > 0 && xianshi_price < goods_price) {
                $.post('<?php echo urlShop('store_promotion_xianshi', 'xianshi_goods_price_edit');?>',
                    {xianshi_goods_id: xianshi_goods_id, xianshi_price: xianshi_price},
                    function(data) {
                        if(data.result) {
                            $edit_item.find('[nctype="xianshi_price"]').text(data.xianshi_price);
                            $edit_item.find('[nctype="xianshi_discount"]').text(data.xianshi_discount);
                            $('#dialog_edit_xianshi_goods').hide();
                        } else {
                            showError(data.message);
                        }
                    }, 'json'
                );
            } else {
                $('#dialog_edit_xianshi_goods_error').show();
            }
        });
        $('#btn_search_goods').trigger("click");
    });
</script>